﻿import streamlit as st

from langchain_core.messages import HumanMessage
from utils.session_state import SessionState, init_session_state
from utils.modules import render_utils

async def arun():
    st.title("default page")
    await init_session_state()
    state:SessionState = st.session_state.state
    state.history.render()
    # --- User input and processing ---
    placeholder0 = st.container()
    user_query = st.chat_input("💬 Enter your question")
    if user_query:
        with placeholder0:
            st.chat_message("user").text(user_query)
            state.history.add_user_message(user_query)
            messages = [HumanMessage(content=user_query)]
            with st.chat_message("assistant"):
                placeholder = st.container()
                resp = await render_utils.ainvoke_with_render(state.get_graph_runnable(), messages, placeholder)
                state.history.add_ai_message(resp)
                st.rerun()

def run():
    st.session_state.event_loop.run_until_complete(arun())
